﻿/* This Component Library is licensed under the GNU General Public License version 2 (GPLv2) 
 * You can use this software and its associated files as you wish so long as derived versions
 * or works based on this library are also freely released.
 * If you require a commercial licence for this software without the above restrictions please
 * contact me via scott_blood@hotmail.com or via CodePlex.
 * (c) 2010 Scott Blood
 * Visit SGBControls.CodePlex.com for the latest version of this library.
 */ 
  
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace SGBControls.Editors
{
    public class ControlPainter
    {
        private Graphics graphics = null;
        private Rectangle rect;
        private SGBEditStyleController controller;
        
        public ControlPainter(Graphics g, Rectangle r, SGBEditStyleController c)
        {

            graphics = g;
            rect = r;
            controller = c;
        }

        public void Draw()
        {
            switch (controller.BorderStyle)
            {
                case BorderStyles.Flat: DrawFlatBorder(); break;
                case BorderStyles.Raised: DrawRaisedBorder(); break;
                case BorderStyles.Gradient: DrawGradientBorder(); break;
                case BorderStyles.Sunken: DrawSunkenBorder(); break;
                case BorderStyles.Etched: DrawEtchedBorder(); break;
                case BorderStyles.Bump: DrawBorderStyleBump(); break;
            }            
        }

        private void DrawBorderStyleBump()
        {            
            ControlPaint.DrawBorder3D(graphics, rect, Border3DStyle.Bump);
        }

        private void DrawEtchedBorder()
        {
            ControlPaint.DrawBorder3D(graphics, rect, Border3DStyle.Etched);
        }

        private void DrawSunkenBorder()
        {
            ControlPaint.DrawBorder3D(graphics, rect, Border3DStyle.Sunken);
        }

        private void DrawGradientBorder()
        {
            rect.Width -= 1;
            rect.Height -= 1;
            Pen p = new Pen(controller.BorderColor);
            graphics.DrawRectangle(p, rect);

            p = new Pen(Color.FromArgb(100, controller.BorderColor));
            rect.Inflate(-1, -1);
            graphics.DrawRectangle(p, rect);

            p = new Pen(Color.FromArgb(45, controller.BorderColor));
            rect.Inflate(-1, -1);
            graphics.DrawRectangle(p, rect);

            p = new Pen(Color.FromArgb(15, controller.BorderColor));
            rect.Inflate(-1, -1);
            graphics.DrawRectangle(p, rect);

            p.Dispose();
        }

        private void DrawRaisedBorder()
        {
            ControlPaint.DrawBorder3D(graphics, rect, Border3DStyle.Raised);            
        }

        private void DrawFlatBorder()
        {
            rect.Width -= 1;
            rect.Height -= 1;
            Pen p = new Pen(controller.BorderColor);
            graphics.DrawRectangle(p, rect);

            //p = new Pen(Color.FromArgb(100, controller.BorderColor));
            //rect.Inflate(-1, -1);
            //graphics.DrawRectangle(p, rect);

            //p = new Pen(Color.FromArgb(45, controller.BorderColor));
            //rect.Inflate(-1, -1);
            //graphics.DrawRectangle(p, rect);

            //p = new Pen(Color.FromArgb(15, controller.BorderColor));
            //rect.Inflate(-1, -1);
            //graphics.DrawRectangle(p, rect);
        }
    }
}
